<?php
namespace Home\Controller;
use Home\Controller\CommonController;
class OrdersController extends CommonController {

   public function index(){

        $id=I('get.id');
        $ids=I('get.ids');

        if (is_numeric($id)) {
  $arr=M('shangpin')->where('id='.$id)->select();
}

       if (is_array($ids)) {
       foreach ($ids as $key => $value) {
         foreach ($_SESSION['goods'] as $key => $v) {
          if ($value==$v['id']) {
                  
                   $arr[]=$v;

          }
         }
       }

   }




if (isset($_SESSION['userid'])) {
$dizhi=M('address')->where('dzid='.$_SESSION['userid'])->select();
}

$this->assign('goods',$arr);
$this->assign('dizhi',$dizhi);
 
   	$this->display();
   }
    
    public function dingdan(){ 

$model=M('dingdan');
 $data['code']=time().rand(10000,99999);
  $data['time']=time();
  $data['biaoti']=$_POST['liuyan'];
    $data['aid']=$_POST['aid'];
  $data['uid']=$_SESSION['userid'];
   $data['zid']=1;
   $data['fid']=1;
   $result=$model->add($data);
   if($result) {
  for ($i=0; $i < count($_POST['goodid']); $i++) { 

 $data11['order_id']=$result;
 $data11['goods_id']=$_POST['goodid'][$i];
 $data11['gjinz']=$_POST['gjinz'][$i];
 $data11['gyanse']=$_POST['gyanse'][$i];
  $data11['gshul']=$_POST['gshul'][$i];
  M('order_goods')->add($data11);
   }
   };


 for ($i=0; $i < count($_POST['goodid']); $i++) { 
        foreach($_SESSION['goods'] as $key => $value){
          if($_POST['goodid'][$i]==$value['id']){
       
                  unset($_SESSION['goods'][$key]);}
         }

 }
  	$this->redirect('User/dingdan');  


  


}


    



}

?>